package DEEPERsource.DEEPERsource.source.statistics;

import java.util.HashMap;
import java.util.Map;

/**
 * Class stores the frequency of certain object
 * @author tfayruzo
 *
 */
@SuppressWarnings("serial")
public class FreqMap<T> extends HashMap<T, Integer>{
	
	@Override
	public Integer put(T key, Integer value) {
		if(containsKey(key)){
			return super.put(key,get(key).intValue()+value.intValue());
		}else{
			return super.put(key, value);
		}
	}
	
	

	@Override
	public void putAll(Map<? extends T, ? extends Integer> m) {
		for(T key : m.keySet()){
			put(key, m.get(key));
		}
	}

	@Override
	public String toString() {
		StringBuffer sb = new StringBuffer("");
		for(T key : keySet()){
			sb.append(key.toString());
			sb.append("\t");
			sb.append(get(key).toString());
			sb.append("\n");
		}
		return sb.toString();
	}
	
	
}
